package com.code.zg.news.base;


import rx.Subscription;
import rx.subscriptions.CompositeSubscription;

/**
 * Created by zhanggang on 2017/2/25.
 */

public class RxBasePresenter<T extends BaseView> implements BasePresenter<T> {
    protected T mView;
    protected CompositeSubscription compositeSubscription;
    protected void addSubscribe(Subscription subscription){
        if(compositeSubscription==null){
            compositeSubscription=new CompositeSubscription();
        }
        compositeSubscription.add(subscription);
    }
    protected void unsubscribe(){
        if(compositeSubscription!=null){

            compositeSubscription.unsubscribe();
        }
    }
    @Override
    public void attchView(T v) {
        mView=v;

    }

    @Override
    public void detachView() {
        mView=null;
        unsubscribe();
    }

}
